// pages/home/home.js
//const { isTextureWrapper } = require('XrFrame/xrFrameSystem');
var util = require('../../utils/util.js'); 
var app = getApp();
var showModalStatus = app.globalData.showModalStatus;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:'', //今天的日期
    tomorrow:'', //明天
    show:false,
   // showModalStatus: false, //弹出层
    qrcodeResult:'',
    //预约时间段
    recordtime:app.globalData.recordtime,
    username: '',
    userwxid:'', 
   
  },
  showModal: function () { //展示弹出层
    this.setData({
      showModalStatus: true
    });
  },
  hideModal: function () { //隐藏弹出层
    this.setData({
      showModalStatus: false
    });
  },
  scanQRcode: function(){ //扫描二维码的点击事件
    var that = this;
    wx.scanCode({
      onlyFromCamera:true,
      success: function(res){
        that.setData({
          qrcodeResult:res.result
        })
      }
    })
  },
  gotomy(){
    wx.navigateTo({
      url: '/pages/my/my',
    })
  },
  //点击空间图片跳转到对应界面
  gotospace(){
    wx.navigateTo({
      url: '/pages/spaceDetail/spaceDetail',
    })
  },
  gotosearch(){
    wx.navigateTo({
      url: "/pages/search/search",
    })
  },
  gotochooseSeat(e){
    let title = e.currentTarget.dataset.title;
    let item = e.currentTarget.dataset.item;
    let startTime = item.start;
    let endTime = item.end;
    console.log(title);
    wx.navigateTo({
      url: '/pages/chooseSeat/chooseSeat?title=' + title + '&endTime=' + endTime + '&startTime=' + startTime
    })
  },
  gotomyAppointment(){
    if(this.data.userwxid.trim().length == 0)
    {
      wx.hideLoading(); // 隐藏加载提示
      wx.showToast({
        icon:'loading',
        title: '请先登录',
      });
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/login/login',
        });
      }, 1000); // 1000 毫秒等于 1 秒
    }
    else{
      wx.navigateTo({
        url: '/pages/myAppointment/myAppointment',
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.stopPullDownRefresh();
    var DATE = util.formatDate(new Date()); //获取当前时间和明天的日期
    var TOMORROW = util.formattomorrow(new Date());
    this.setData({
      date:DATE,
      tomorrow: TOMORROW
    });
    if(options.showModalStatus){
      this.showModal()
    };
   
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var app = getApp();
    this.setData({
      username: app.globalData.userName,
      userwxid: app.globalData.userWxid,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})